    {include file="public/header"}
<title>订单编辑</title>
</head>
<body>
<style>
</style>

<article class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-member-add">
        <input type="hidden" name="order_id" value="{$res.order_id}">
        <div class="ch-row ch-info-form">
            <p class="flex1">渠道：</p>
            <div class="flex2">
                <select class="form-control" size="1px" name="channel_id">
                    <option value="{$res['channel_id']}" selected="selected">{$res['title']}</option>
                    {volist name='chanel' id='v'}
                    <option value="{$v.id}">{$v.title}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <p class="flex1">问题：</p>
            <div class="flex2 ch-pc-row">
                <select  class="form-control goods_category ch-info-select"name="pro_id">
                    <option selected="selected" value="{$res['pro_id']}">{$res['pro_ids']}</option>
                    {volist name='go' id='v'}
                    <option value="{$v.id}">{$v.title}</option>
                    {/volist}
                </select>
                <select class="form-control goods ch-info-select"name="pro_id1">
                    <option selected="selected" value="{$res['pro_id']}">{$res['pro_ids1']}</option>

                </select>
                <select  class="form-control good" name="pro_id2">
                    <option selected="selected" value="{$res['pro_id']}">{$res['pro_ids2']}</option>
                </select>
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <p class="flex1">时间：</p>
            <div class="flex2 ch-row ch-info-time">
                <input type='text' name="created_time"  id='datetimepicker2' value=" {:date('Y-m-d H:i:s',$res.created_time)}"/>
                <p class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </p>
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <p class="flex1">地址：</p>
            <div class="flex2">
                <div class="ch-pc-row">
                    <select name="province_id" class="province form-control ch-info-select" onclick="privance()">
                        <option selected="selected" value="{$res.province_id}">{$res.province}</option>
                    </select>
                    <select name="city_id" class="city form-control ch-info-select">
                        <option selected="selected" value="{$res.city_id}">{$res.city}</option>
                    </select>
                    <select name="county_id" class="area form-control">
                        <option selected="selected" value="{$res.county_id}">{$res.county}</option>
                    </select>
                </div>
                
                <input type="text" name="addres" value="{$res.addres}" class="form-control" style="margin-top: 5px;">
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <p class="flex1">联系人：</p>
            <div class="flex2 ch-row">
                <input type="text" class="form-control" value="{$res['contacts']}" name="contacts">
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <p class="flex1">联系电话：</p>
            <div class="flex2 ch-row">
                <input type="text" class="form-control" value="{$res['telephone']}" name="telephone">
            </div>
        </div>
	  <div class="ch-row ch-info-form">
            <p class="flex1">小区名称：</p>
            <div class="flex2 ch-row">
                <input type="text" class="form-control" value="{$res['residential_quarters']}" name="residential_quarters">
            </div>
        </div>
	<div class="ch-row ch-info-form">
            <p class="flex1">所属物业：</p>
            <div class="flex2">
                <select class="form-control ch-info-select" size="1px" name="residential_id" >
                    <?php if(!empty($res['residential_id'])){ ?>
                    {volist name='title' id='v'}
                    <?php if($res['residential_id']== $v['residential_id']){ ?>
                    <option value="{$v.residential_id}" selected>{$v.content}</option>
                       <?php }else{ ?>
                    <option value="{$v.residential_id}">{$v.content}</option>
                   <?php }?>
                    {/volist}
                    <?php }else{ ?>
                    <option value="" selected="selected">请选择所属物业</option>
                    {volist name='title' id='v'}

                    <option value="{$v.residential_id}">{$v.content}</option>
                    {/volist}
                    <?php }?>
                </select>
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <p class="flex1">推荐人：</p>
            <div class="flex2 ch-row">
                <input type="text" class="form-control" value="{$res['management']}"  name="management">
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <p class="flex1">备注：</p>
            <div class="flex2 ch-row">
                <textarea placeholder="请输入备注"  name="remarks">{$res['remarks']}</textarea>
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <p class="flex1"><span class="c-red">*</span>图片：</p>
            <div class="flex2">
                <div id="uploader-demo">
                    <!--用来存放item-->
                    <div id="fileList" class="uploader-list">
                      <?php if(is_array($res['logo']))foreach($res['logo'] as $user){ ?>
                        <div id="" class="file-item thumbnail">
                            <div onclick="delParent(this)" style="cursor: pointer;background: url({$Think.DOMAIN_SRC}/static/h-ui/images/del.png) no-repeat;background-size:contain;height: 20px;width: 20px;position: absolute;z-index: 10;right: 5px;"></div>
                            <img style="width: 100px;height: 100px;" src="<?php echo $user ?>">
                            <input name="logo[]" type="hidden" value="<?php echo $user ?>">
                            <div class="info"></div>
                        </div>
                       <?php } ?>
                    </div>
                    <div id="filePicker">选择图片</div>
                </div>
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <div class="flex1">
                <button class="btn btn-primary radius" type="button"><i class="Hui-iconfont">&#xe632;</i> 提交</button>
            </div>
        </div>
         

    </form>
</article>
{include file="public/footer"}
<script>
    $('.radius').click(function () {
        var src="{:Url('index/order/edit')}";
        $.ajax({
            type: 'POST',
            url: src,
            dataType: 'json',
            data:$('form').serializeArray(),
            success: function (data) {
                var res=JSON.parse(data);
                if(res.code==200){
                    layer.msg(res.msg, {icon: 1, time: 2000}, function (index,layero) {
                        parent.location.reload()
                    });
                }else{
                    layer.msg(res.msg,{icon: 5,time:1000});
                }

            },
            error: function (data) {
                console.log(data.msg);
            },
        });

    });

    $('.goods_category').bind("change", function () {
        //向input输入框中赋值
        goods();
    });
    $(".goods").bind("change", function () {
        good()
    });


    function goods() //市
    {
        var parent_ids = $(".goods_category option:selected").val();
        $.post("{:url('index/order/goods_category')}", {parent_id: parent_ids}, function (data, textStatus, xhr) {
            var html;
            if (data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    html += "<option value='" + data[i]['id'] + "'>" + data[i]['title'] + "</option>";
                }

            } else {
                html += "<option value=''>暂无数据</option>";

            }

            $('.goods').html(html);
            good();


        });
    }


    function good() {
        var parent_id = $('.goods').val();
        var html;

        if (parent_id) {
            $.post("{:url('index/order/goods_category')}", {parent_id: parent_id}, function (data, textStatus, xhr) {

                if (data.length > 0) {
                    for (var i = 0; i < data.length; i++) {
                        html += "<option value='" + data[i]['id'] + "'>" + data[i]['title'] + "</option>";

                    }
                } else {
                    html += "<option value=''>暂无数据</option>";
                }

                $('.good').html(html);

            });
        } else {
            html += "<option value=''>暂无数据</option>";
            $('.good').html(html);
        }

    }

    $("#img-change").click(function () {
        $("#file").click();
    });

    function delParent(object){
        $(object).parent().remove();
        count-=1;
    }
    var count=1;
    $(function(){
        var $list = $("#fileList");
        var uploader = WebUploader.create({
            auto: true,
            // 文件接收服务端。
            server: "{:Url('index/upload/upload_file')}",

            // 选择文件的按钮。可选。
            pick: '#filePicker',

            // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
            resize: false,
            duplicate:true,
            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/*'
            },
        });

        // 当有文件添加进来的时候
        uploader.on( 'fileQueued', function( file ) {
            var $li = $(
                    '<div id="' + file.id + '" class="file-item thumbnail">' +
                    '<div onclick="delParent(this)" style="cursor: pointer;background: url({$Think.DOMAIN_SRC}/static/h-ui/images/del.png) no-repeat;background-size:contain;height: 20px;width: 20px;position: absolute;z-index: 10;right: 5px;"></div>'+
                    '<img style="width: 100px;height: 100px;">' +
                    '<input name="logo[]" type="hidden" value="">'+
                    '<div class="info">' + file.name + '</div>' +
                    '</div>'
                ),
                $img = $li.find('img');


            // $list为容器jQuery实例
            $list.append( $li );

            // 创建缩略图
            // 如果为非图片文件，可以不用调用此方法。
            // thumbnailWidth x thumbnailHeight 为 100 x 100
            uploader.makeThumb( file, function( error, src ) {
                if ( error ) {
                    $img.replaceWith('<span>不能预览</span>');
                    return;
                }

                $img.attr( 'src', src );
            }, 100, 100 );
        });



        // 文件上传过程中创建进度条实时显示。
        uploader.on( 'uploadProgress', function( file, percentage ) {
            var $li = $( '#'+file.id ),
                $percent = $li.find('.progress span');

            // 避免重复创建
            if ( !$percent.length ) {
                $percent = $('<p class="progress"><span></span></p>')
                    .appendTo( $li )
                    .find('span');
            }


            $percent.css( 'width', percentage * 100 + '%' );
        });
    var s=[];
        // 文件上传成功，给item添加成功class, 用样式标记上传成功。
        uploader.on( 'uploadSuccess', function( file,res ) {
            var data = JSON.parse(res._raw);
            if(data.errcode==300){
                layer.alert(data.msg);
            }
            var url = data.data;
            count+=1;
            $( '#'+file.id).find("logo").attr("src",url);
            $( '#'+file.id).find("input").val(url);
            $( '#'+file.id ).addClass('upload-state-done');
        });

        // 文件上传失败，显示上传出错。
        uploader.on( 'uploadError', function( file ) {
            var $li = $( '#'+file.id ),
                $error = $li.find('div.error');

            // 避免重复创建
            if ( !$error.length ) {
                $error = $('<div class="error"></div>').appendTo( $li );
            }

            $error.text('上传失败');
        });

        // 完成上传完了，成功或者失败，先删除进度条。
        uploader.on( 'uploadComplete', function( file ) {
            $( '#'+file.id ).find('.progress').remove();
        });
    });



</script>
</body>
</html>
